#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int x;
	cin >> x;
	int res = 0;
	int l = 1, r = x;
	while (l <= r) {
		int m = l + (r - l) / 2;
		int cnt = m;
		while (m / 3 != 0) {
			cnt += m / 3;
			m = m / 3 + m % 3;
		}
		if (cnt < x) {
			l = l + (r - l) / 2 + 1;
		} else {
			if (cnt == x) {
				cout << l + (r - l) / 2;
				return 0;
			}
			r = l + (r - l) / 2 - 1;
			res = l + (r - l) / 2;
		}
	}
	cout << res;
	return 0;
}
